<%--
  Created by IntelliJ IDEA.
  User: zhou
  Date: 2018/1/25
  Time: 16:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        var jsonUser=JSON.stringify({
            "username":"张三",
            "age":"111",
            "address":"南京"
        });

        function requestJson() {
            $.ajax({
                type:"POST",
                url:"${pageContext.request.contextPath}/user/requestJson.do",
                contentType:"application/json;charset=utf-8",
                data:jsonUser,
                success:function (data) {
                    alert(data.username)
                }
            })
        }
        function requestPojo() {
            $.ajax({
                type:"POST",
                url:"${pageContext.request.contextPath}/user/requestPojo.do",
                data:"username=张三&age=11&address=南京",
                success:function (data) {
                    alert(data.username)
                }
            })
        }
    </script>
</head>
<body>
<input type="button" value="请求json，返回json" onclick="requestJson();">
<input type="button" value="请求pojo，返回json" onclick="requestPojo();">
</body>
</html>
